import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { persistReducer,persistStore } from "redux-persist";
import storage from 'redux-persist/lib/storage'

import userInfo from "./modules/userInfo";
import theme from "./modules/theme";


const reducer = combineReducers({
  userInfo: userInfo,
  theme
})


const persistConfig = {
  key: 'start',
  storage,
  whitelist: ["userInfo"]
}

const persistedReducer = persistReducer(persistConfig, reducer)

const store = configureStore({
  reducer: persistedReducer
});

export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;

export const persistor = persistStore(store);

export default store;